package com.server.modules.sys.scheduled;

import com.server.modules.api.service.IMService;
import com.server.modules.sys.entity.member.Member;
import com.server.modules.sys.service.member.MemberService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by 金贤哲 on 2017/3/14 0014.
 */
@Component
public class ScheduleBirthdaySendTask {

    @Resource
    private MemberService memberService;
    @Resource
    private IMService imService;


    @Scheduled(cron = "0 35 9 * * ?") //每天九点检测客户生日，发送生日祝福
    public void taskbirthday() {
        List<Member> taskbirthdays = memberService.birthdaysend();
        Map<String, String> msg = new HashedMap();
        msg.put("type", "text");
        msg.put("msg", "尊敬的客户，在您生日到来之际，贷贷帮金融全体员工祝您生日快乐，生日惊喜：办理业务有优惠，详询：4000717176！");
        List<String> userList = new ArrayList<String>(1);
        for (Member member : taskbirthdays) {
            userList.add(member.getHxUsername());
        }
//        for (int i = 0; i < userList.size(); i++) {
//            System.out.println(userList.get(i));
//        }
        imService.sendSysMessages(userList, msg, null);

    }
}
